<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="财年">
              <a-date-picker
                mode="year"
                placeholder="请选择财年"
                format='YYYY'
                valueFormat="YYYY"
                v-decorator="[ 'bgYear', queryParam.bgYear]"
                style="width:100%"
                :open='yearShowOne'
                @openChange="openChangeOne"
                @panelChange="panelChangeOne"
                v-model="queryParam.bgYear"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="季度">
                <a-select efault-value="form.bgQuarter"
                          v-decorator="[ 'bgQuarter', {}]"
                          placeholder="请输入季度"  v-model="queryParam.bgQuarter"
                          :getPopupContainer = "(target) => target.parentNode">
                  <a-select-option value="1">第一季度</a-select-option>
                  <a-select-option value="2">第二季度</a-select-option>
                  <a-select-option value="3">第三季度</a-select-option>
                  <a-select-option value="4">第四季度</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="月度">
                <a-month-picker placeholder="请输入月度"  v-model="queryParam.bgMonth" format='MM' valueFormat="MM" v-decorator="[ 'bgMonth',{}]"/>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('预算财年')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      <a-button type="primary" icon="start" @click="startorstop('009')">启用</a-button>-->
<!--      <a-button type="primary" icon="stop" @click="startorstop('003')">停用</a-button>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <tpmBudgetYear-modal ref="modalForm" @ok="modalFormOk"></tpmBudgetYear-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import TpmBudgetYearModal from './modules/TpmBudgetYearModal'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import JDate from '@/components/cn-form/JDate'
  import { getAction } from '@/api/manage'
  import moment from 'moment'

  export default {
    name: "TpmBudgetYearList",
    mixins:[PageListMixin],
    components: {
      TpmBudgetYearModal,
      JDate
    },
    data () {
      return {
        description: '预算财年管理页面',
        yearShowOne:false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
          {
            title: '财年',
            align:"center",
            dataIndex: 'bgYear'
          },
          {
            title: '季度',
            align:"center",
            dataIndex: 'bgQuarter',
            customRender: function (text) {
              if (text === '1') {
                return '第一季度'
              } else if (text === '2') {
                return '第二季度'
              } else if (text === '3') {
                return '第三季度'
              } else if (text === '4') {
                return '第四季度'
              } else {
                return text
              }
            }
          },
          {
            title: '月度',
            align:"center",
            dataIndex: 'bgMonth'
          },
          {
            title: '费用开始',
            align:"center",
            dataIndex: 'bgStartDate'
          },
          {
            title: '费用结束',
            align:"center",
            dataIndex: 'bgEndDate'
          },
		   {
            title: '创建人姓名',
            align:"center",
            dataIndex: 'createName'
           },
		   {
            title: '创建时间',
            align:"center",
            dataIndex: 'createDate'
           },
		   {
            title: '更新时间',
            align:"center",
            dataIndex: 'updateDate'
           },
		   {
            title: '更新人姓名',
            align:"center",
            dataIndex: 'updateName'
           },
		   {
            title: '停用启用状态',
            align:"center",
            dataIndex: 'status',
            customRender: function (text) {
              if (text === '009') {
                return '启用'
              } else {
                return '停用'
              }
            }
            },
		   {
            title: '是否删除',
            align:"center",
            dataIndex: 'deleteStatus',
           customRender: function (text) {
           if (text === '009') {
             return '否'
           } else {
             return '是'
           }
         }
           },
		   {
            title: '备注',
            align:"center",
            dataIndex: 'remarks'
           },

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: window._CONFIG['domianTpmURL']+"/budget/tpmBudgetYear/findPageList",
          delete: window._CONFIG['domianTpmURL']+"/budget/tpmBudgetYear/delete",
          deleteBatch: window._CONFIG['domianTpmURL']+"/budget/tpmBudgetYear/deleteBatch",
          exportXlsUrl: window._CONFIG['domianTpmURL']+"budget/tpmBudgetYear/exportXls",
          importExcelUrl: window._CONFIG['domianTpmURL']+"budget/tpmBudgetYear/importExcel",
          startOrStopUrl: window._CONFIG['domianTpmURL']+"budget/tpmBudgetYear/startOrStop",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },

  },
    methods: {
      openChangeOne(status){
        //status是打开或关闭的状态
        if(status){
          this.yearShowOne =  true
        }
      },
      panelChangeOne(value){
        this.queryParam.bgYear=moment(value).format('YYYY');
        // this.queryParam.setFieldsValue({
        //   bgYear: moment(value).format('YYYY')
        // })
        this.yearShowOne = false
      },
      startorstop: function(status) {
        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return
        }
        if (this.selectedRowKeys.length != 1) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var id = this.selectedRowKeys[0];
          var that = this;
          that.loading = true;
          getAction(this.url.startOrStopUrl, {id: id,status: status}).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.loadData();
            } else {
              that.$message.warning(res.message);
            }
            that.loading = false;
          });
        }


      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>